package com.yonyougov.devops.cruxcisupport;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.mail.javamail.JavaMailSenderImpl;

/**
 * JavaMailSender 实现类
 */
@Configuration
public class MailConfiguration {
    private final Logger logger = LoggerFactory.getLogger(MailConfiguration.class);
    @Value("${spring.mail.host}")
    private String MAIL_HOST;
    @Value("${spring.mail.username}")
    private String MAIL_USERNAME;
    @Value("${spring.mail.password}")
    private String MAIL_PASSWORD;
    @Bean
    public JavaMailSenderImpl JavaMailSender(){
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
        logger.info("mail host is : " + MAIL_HOST);
        logger.info("mail username is : " + MAIL_USERNAME);
        logger.info("mail password is : " + MAIL_PASSWORD);
        mailSender.setHost(MAIL_HOST);
        mailSender.setUsername(MAIL_USERNAME);
        mailSender.setPassword(MAIL_PASSWORD);
        return mailSender;
    }


    @Bean
    public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
        return new PropertySourcesPlaceholderConfigurer();
    }
}